package com.by.toolkit.model;

import com.by.toolkit.model.apiannotation.Page;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
 * 分页请求统一参数
 *
 * @author YanBingHao
 * @since 2023/12/27
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ESPageReq<T> implements Serializable {

    @NotNull(groups = Page.class, message = "每页条数不能为空")
    @Max(value = 5000, message = "分页条数不能超过5000")
    private Integer pageSize;

    private List<Object> searchAfter;

    @NotNull(groups = Page.class, message = "查询条件不能为空")
    @Valid
    private T condition;

    public static <T> ESPageReq<T> of(Integer pageSize, List<Object> searchAfter, T condition) {
        return new ESPageReq<T>(pageSize, searchAfter, condition);
    }

}
